<html>
<head><meta charset="utf-8"><title>generic trait for generic struct · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20trait.20for.20generic.20struct.html">generic trait for generic struct</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="166996480"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20trait%20for%20generic%20struct/near/166996480" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Papp <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20trait.20for.20generic.20struct.html#166996480">(May 31 2019 at 13:26)</a>:</h4>
<p>Suppose I have the following struct</p>
<div class="codehilite"><pre><span></span><span class="k">struct</span> <span class="nc">Point</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="n">x</span>: <span class="nc">T</span><span class="p">,</span><span class="w"></span>
<span class="w">  </span><span class="n">y</span>: <span class="nc">T</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<p>And also I have a generic trait defined in the following way:</p>
<div class="codehilite"><pre><span></span><span class="k">trait</span><span class="w"> </span><span class="n">SomeTrait</span><span class="o">&lt;</span><span class="n">U</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="k">fn</span> <span class="nf">do_stuff</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">x</span>: <span class="nc">U</span><span class="p">)</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="166996512"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20trait%20for%20generic%20struct/near/166996512" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Papp <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20trait.20for.20generic.20struct.html#166996512">(May 31 2019 at 13:27)</a>:</h4>
<p>And I want to implement the generic trait for the generic struct. How do I do that?</p>



<a name="166996889"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20trait%20for%20generic%20struct/near/166996889" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20trait.20for.20generic.20struct.html#166996889">(May 31 2019 at 13:31)</a>:</h4>
<p><code>impl&lt;V&gt; SomeTrait&lt;V&gt; for Point&lt;V&gt; {}</code> (can also just use <code>T</code> instead of <code>V</code>)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>